« How to Manipulate the HTML Document Object inside the .Net WebBrowser Control? »
Thu July-19-2007, 8:34:37 PM
This example shows you how you can manipulate the Document Object inside the .Net WebBrowser Control. You can easily add functionality such as auto form fill and auto button click and auto link click into your application with the WebBrowser Control.

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        WebBrowser1.Navigate("http://search.yahoo.com/")
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        WebBrowser1.Document.DomDocument.all.p.value = "darong"
        WebBrowser1.Document.GetElementsByTagName("Input").Item(3).InvokeMember("Click")
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim Y As Integer
        For Y = 0 To WebBrowser1.Document.GetElementsByTagName("A").Count - 1

            Dim href As String
            href = WebBrowser1.Document.GetElementsByTagName("A").Item(Y).GetAttribute("href")
            If (href.Contains("www.madarong.com")) Then
                WebBrowser1.Document.GetElementsByTagName("A").Item(Y).InvokeMember("Click")
                Exit Sub
            End If
        Next

        Dim X As Integer
        For X = 0 To WebBrowser1.Document.GetElementsByTagName("A").Count - 1
            Dim AT As String
            AT = WebBrowser1.Document.GetElementsByTagName("A").Item(X).GetAttribute("title")
            If (AT.Contains("Results")) Then
                WebBrowser1.Document.GetElementsByTagName("A").Item(X).InvokeMember("Click")
                Exit For
            End If
        Next
    End Sub
End Class